import requests
import webbrowser
# get:从网页上获取信息
base_url = 'https://www.baidu.com/s'     # /s不要漏，后面根据param字典生成对应key = value
param = {'wd':'inquiry'}
response = requests.get(base_url,params=param)
webbrowser.open(response.url)           # 使用默认浏览器打开url
# post:向网页提交信息并得到反馈
# 提交文字信息
data = {'firstname':'BH','lastname':'Z'}
url1 = 'https://pythonscraping.com/pages/files/processing.php'  # 注意这个是post的目标网站！
response = requests.post(url1,data=data)
print(response.text)
# 登录
login = {'username':'ZBH','password':'12354'}
url2 = 'https://pythonscraping.com/pages/cookies/welcome.php'
url22 ='https://pythonscraping.com/pages/cookies/profile.php'
response = requests.post(url2,data=login)
cookies = response.cookies
print(cookies.get_dict())
r = requests.get(url22,cookies = cookies)
print(r.text)
# 使用Session登录
session = requests.session()
r = session.post(url2,data)
print(r.cookies.get_dict())
r = requests.get(url22)
print(r.text)
# 提交图片
file = {'uploadFile':open('AC.jpg','rb')}
url3 = 'https://pythonscraping.com/pages/files/processing2.php'
response = requests.post(url3,files=file)
print(response.text)